package ch6.ex12;

import static ch6.print.Print.*;

class Component1{
	public Component1(int i) {
		println("Component1 " + i);
	}
	public void dispose(){
		println("Component1 dispose");
	}
}

class Component2{
	public Component2(int i) {
		println("Component2 " + i);
	}
	public void dispose(){
		println("Component2 dispose");
	}
}

class Component3{
	public Component3(int i) {
		println("Component3 " + i);
	}
	public void dispose(){
		println("Component3 dispose");
	}
}

class Root{
	Component1 c1 = new Component1(1);
	Component2 c2 = new Component2(2);
	Component3 c3 = new Component3(3);
	
	public Root(int i) {
		println("Root");
	}
	public void dispose(){
		println("Root dispose");
		c3.dispose();
		c2.dispose();
		c1.dispose();
	}
}

class Stem extends Root{
	Component1 c1 = new Component1(4);
	Component2 c2 = new Component2(5);
	Component3 c3 = new Component3(6);
	
	public Stem(int i) {
		super(i);
		println("Stem");
	}
	public void dispose(){
		println("Stem dispose");
		c3.dispose();
		c2.dispose();
		c1.dispose();
		super.dispose();
	}
}

public class ConstructorOrder {
	public static void main(String... args){
		new Stem(1).dispose();
	}

}
